package com.sg.util;

import org.apache.log4j.Logger;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.io.File;
import java.util.Date;

/**
 * @author wangcf
 * @Description 创建新文件名工具类
 * @date 2023/3/16 11:05
 */
public class NewFile {
    private static Logger logger=Logger.getLogger(NewFile.class);

    public static String getNewFileNameAnd(String fileName){
        return "/div/"+fileName;//文件分割符
    }

    public static File getFile(CommonsMultipartFile file) {
        //String path = "E:" + File.separator + "div" + File.separator;//文件分割符
        String path = "E:" + File.separator + "div" + File.separator;//文件分割符
        logger.info(path);
        String fileName = file.getOriginalFilename();//得到原始名称
        String fileType = fileName.substring(fileName.lastIndexOf("."));//截取文件后缀
        logger.info(fileType);
        File file2 = new File(path+new Date().getTime() +Math.random()+ fileType);
        logger.info(file2);
        logger.info(new Date().getTime());
        return file2;
    }
}
